class Solution:
    def longestPalindrome(self, s: str) -> str:
        length = len(s)
        if len(s) == 1:
            return s
        if len(s) == 2:
            return s if s[0] == s[1] else s[0]
        palindrome_str = s[0]
        for i in range(length):
            if length +1 -i < len(palindrome_str):
                break
            for j in range(length-1,i,-1):
                if s[j] == s[i]:
                    if self.is_palindrome(s[i:j+1]):
                        if j+1-i > len(palindrome_str):
                            palindrome_str = s[i:j+1]
                            break

        return palindrome_str
    def is_palindrome(self,s:str):
        start = 0
        end = len(s)-1
        while start<end:
            if s[start] != s[end]:
                return False
            start+=1
            end -=1
        return True


print(Solution().longestPalindrome("cbbd"))
